package com.example.springbootxscjxt.controller;

import com.example.springbootxscjxt.entity.User;
import com.example.springbootxscjxt.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Controller
@RequestMapping("/score")
public class UserController {
@Autowired
    private UserMapper userMapper;
@GetMapping("/login")
public Map<String ,Object> login(@RequestParam String username,@RequestParam String password,@RequestParam int type){
    System.out.println(type);
    Map<String,Object> res=new HashMap<>();
    List<User> data=null;
    if(type == 1){
       data=userMapper.login(username,password);

    }else{
        data=userMapper.login1(username,password);

    }
System.out.println(data.isEmpty());
    if(type ==2 && data.isEmpty() == true){
        res.put("code",500);
        res.put("msg","请使用学号登录");

    }else if(type == 1 && data.isEmpty() == true){
        res.put("code",500);
        res.put("msg","用户名或密码错误");

    }else{
        res.put("code",200);
        res.put("msg","登录成功");
        res.put("data",data);

    }
    return res;

}
}
